package day07;

import day09.Order;

import java.util.Arrays;
import java.util.Scanner;

public class MyOrderingMgs {
    public static void main(String[] args) {
        String[] dishName = {"红烧带鱼","鱼香肉丝","时令蔬菜"}; //菜品名字
        double[] dishPrice={38,20,10};  //菜品价格
        int[] dishLove = {0,0,0}; //客户点赞数，初始值为0

        String[] orderNames={}; //订单人的名字
        double[] orderDishPrice={}; //订单上菜品的价格
        String[] orderDishNames={}; //订单上菜品的名字
        int[] orderCounts={}; //订单菜品的个数
        double[] totalPrices={}; // 菜品单价*菜品个数 =菜品总价
        int[] orderDates ={}; // 送餐时间
        String[] addresss = {}; // 送餐地址
        int[] orderSates ={}; //订单状态
        int choose = 0;      //用户输入的信息
        int songcanfei = 0;
        double canfei =0;
        double zongji =0;
       do {
           System.out.println("欢迎使用“吃货联盟订餐系统");
           System.out.println("******************************");
           System.out.println("1, 我要订餐");
           System.out.println("2, 查看订单");
           System.out.println("3, 签收订单");
           System.out.println("4, 删除订单");
           System.out.println("5, 我要点赞");
           System.out.println("6, 退出系统");
           System.out.println("******************************");
           System.out.println("请选择：");
           Scanner input = new Scanner(System.in);
           choose = input.nextInt();
           System.out.println("你选择的是："+choose);

           switch (choose){
               case 1:
                   orderNames = Arrays.copyOf(orderNames,orderNames.length+1);
                   orderDishPrice =  Arrays.copyOf(orderDishPrice,orderDishPrice.length+1);
                   orderDishNames = Arrays.copyOf(orderDishNames,orderDishNames.length+1);
                   orderCounts = Arrays.copyOf(orderCounts,orderCounts.length+1);
                   orderDates = Arrays.copyOf(orderDates,orderDates.length+1);
                   addresss = Arrays.copyOf(addresss,addresss.length+1);
                   orderSates = Arrays.copyOf(orderSates,orderSates.length+1);
                   totalPrices= Arrays.copyOf(totalPrices,totalPrices.length+1);
                   System.out.println("***我要订餐***");
                   System.out.println("请输入订餐人姓名：");
                   int lastIndex = orderNames.length-1;
                   orderNames[lastIndex ] = input.next();
                   for (int i=0;i<dishName.length;i++){
                       System.out.println((i+1)+"\t"+dishName[i]+"\t"+dishPrice[i]+"元"+"\t"+dishLove[i]);
                   }
                   System.out.println("请选择您要点的菜品编号:");
                   int num1 = input.nextInt();
                   orderDishNames[lastIndex] = dishName[num1 -1];
                   orderDishPrice[lastIndex] = dishPrice[num1 -1];
                   System.out.println("请选择您需要的份数:");
                   orderCounts[lastIndex]= input.nextInt();
                   System.out.println("请输入送餐时间（送餐时间是10点至20点间整点送餐）:");

                   orderDates[lastIndex] = input.nextInt();

                   System.out.println("请输入送餐地址：");
                   addresss[lastIndex]= input.next();

                   System.out.println("订单成功");

                   System.out.println("你的订单是：");
                   System.out.println(orderDishNames[lastIndex]+"\t"+orderCounts[lastIndex]);
                   System.out.println("送餐时间：");
                   System.out.println(orderDates[lastIndex]+"点");

                   canfei =orderCounts[lastIndex]*dishPrice[lastIndex];
                   zongji = canfei+ songcanfei;
                   totalPrices[lastIndex] =zongji;
                   System.out.println("餐费："+canfei +"\t"+"送餐费0.0元"+"\t"+ "总计："+totalPrices[lastIndex] );
                   System.out.println("输入0返回：");

                   choose = input.nextInt();
                   break;
               case 2:
                   System.out.println("***查看订单***");
                   System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态");
                   for (int i = 0; i <orderDishNames.length; i++) {

                       System.out.println((i+1)+"\t"+orderNames[i]+"\t\t"+orderDishNames[i]
                               +"\t\t"+orderDates[i]+"\t\t"+addresss[i]
                               +"\t\t"+totalPrices[i]+"\t"+(orderSates[i]>0?"已完成":"待定"));
                   }
                   System.out.println("输入0返回：");
                   choose = input.nextInt();
                   break;
               case 3:

                   System.out.println("***签收定单***");
                   System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址\t\t总金额\t订单状态");
                   for (int i = 0; i <orderNames.length; i++) {

                       System.out.println((i+1)+"\t"+orderNames[i]+"\t\t"+orderDishNames[i]
                               +"\t\t"+orderDates[i]+"\t\t"+addresss[i]
                               +"\t\t"+totalPrices[i]+"\t"+(orderSates[i]>0?"已完成":"待定"));
                   }
                   System.out.println("请选择要签收的订单序号：");
                   int index4 = input.nextInt();
                   if (orderSates[index4-1]==0){
                       //orderSates[index4-1]=1;

                       System.out.println("签收成功");
                   }else {
                       System.out.println("已完成签收，请勿二次操作");
                   }
                   System.out.println("输入0返回:");
                   choose = input.nextInt();
                   break;
               case 4:

                   System.out.println("***删除订单***");
                   System.out.println("序号\t订餐人\t餐品信息\t\t送餐日期\t送餐地址");
                   for (int i=0;i<orderNames.length-1;i++){
                       System.out.println((i+1)+"\t"+orderNames[i]+"\t"+
                               orderDishNames[i]+"\t\t"+orderDates[i]+"\t"+addresss[i]);
                   }
                   System.out.println("请输入要删除的订单序号:");
                   int index5 = input.nextInt();
                   int start = index5-1;
                   for(int i=start;i<orderNames.length-1;i++){
                       orderNames[i]=orderNames[i+1];
                       orderDishNames[i] =orderDishNames[i+1];
                       orderDishPrice[i] = orderDishPrice[i+1];
                       orderCounts[i] = orderCounts[i+1];
                       totalPrices[i] =totalPrices[i+1];
                       orderDates[i] =orderDates[i+1];
                       addresss[i] = addresss[i+1];
                       orderSates[i] =orderSates[i+1];
                   }
                   orderNames =Arrays.copyOf(orderNames,orderNames.length-1);
                   orderDishNames =Arrays.copyOf(orderDishNames,orderDishNames.length-1);
                   orderDishPrice =Arrays.copyOf(orderDishPrice,orderDishPrice.length-1);
                   orderCounts = Arrays.copyOf(orderCounts,orderCounts.length-1);
                   orderDates = Arrays.copyOf(orderCounts,orderCounts.length-1);
                   addresss =Arrays.copyOf(addresss,addresss.length-1);
                   totalPrices = Arrays.copyOf(totalPrices,totalPrices.length-1);
                   orderSates = Arrays.copyOf(orderSates,orderSates.length-1);
                   System.out.println("删除订单成功");
                   System.out.println("输入0返回：");
                   choose = input.nextInt();
                   break;
               case 5:
                   System.out.println("***我要点赞***");
                   System.out.println("序号\t菜名\t单价");
                   for (int i=0;i<dishName.length;i++){
                       System.out.println((i+1)+"\t"+dishName[i]+"\t"+dishPrice[i]+"元"+"\t"+dishLove[i]);
                   }
                   System.out.println("请输入要点赞的菜品序列号：");
                   int index6 = input.nextInt();
                  dishLove[index6-1] = dishLove[index6-1]+1;
                   System.out.println("点赞成功");
                   System.out.println("输入0返回：");
                   choose = input.nextInt();
                   break;
               case 6:
                   System.out.println("进入菜单6");
                   System.out.println("谢谢使用，欢迎下次光临！");
                   System.exit(0);
                   break;
               default:
                   System.out.println("你的输入有误,没有此菜单");
           }
       }while (choose==0);
    }
}
